#
# Copyright (c) 2017-2023 the rbfx project.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

@PACKAGE_INIT@

# Capture imported targets before including our export file
get_property(_targets_before DIRECTORY PROPERTY IMPORTED_TARGETS)

# Find the tools export file
include(${CMAKE_CURRENT_LIST_DIR}/Urho3DTools.cmake)

# Capture imported targets after including our export file
get_property(_targets_after DIRECTORY PROPERTY IMPORTED_TARGETS)

# Find targets that were added by our export file
set(_our_targets)
foreach(_target IN LISTS _targets_after)
    list(FIND _targets_before ${_target} _found)
    if(_found EQUAL -1)
        list(APPEND _our_targets ${_target})
    endif()
endforeach()

# Set up configuration mapping only for our targets
foreach(_target IN LISTS _our_targets)
    if(TARGET ${_target})
        # Set up fallback configurations for maximum compatibility
        # Each configuration will try its exact match first, then fallback to other available configurations
        set_property(TARGET ${_target} APPEND PROPERTY MAP_IMPORTED_CONFIG_DEBUG DEBUG RELWITHDEBINFO RELEASE MINSIZEREL NONE)
        set_property(TARGET ${_target} APPEND PROPERTY MAP_IMPORTED_CONFIG_RELEASE RELEASE RELWITHDEBINFO DEBUG MINSIZEREL NONE)
        set_property(TARGET ${_target} APPEND PROPERTY MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELWITHDEBINFO RELEASE DEBUG MINSIZEREL NONE)
        set_property(TARGET ${_target} APPEND PROPERTY MAP_IMPORTED_CONFIG_MINSIZEREL MINSIZEREL RELEASE RELWITHDEBINFO DEBUG NONE)
        set_property(TARGET ${_target} APPEND PROPERTY MAP_IMPORTED_CONFIG_NONE NONE RELEASE RELWITHDEBINFO DEBUG MINSIZEREL)
    endif()
endforeach()

# Clean up temporary variables
unset(_targets_before)
unset(_targets_after)
unset(_our_targets)
unset(_target)
unset(_found)

set(Urho3DTools_FOUND TRUE)

check_required_components(Urho3DTools)
